package main

import (
	"context"
	"fmt"
	"github.com/sirupsen/logrus"
	clientv3 "go.etcd.io/etcd/client/v3"

	"time"
)

func main() {
	cli, err := clientv3.New(clientv3.Config{
		Endpoints:   []string{"127.0.0.1:2379"},
		DialTimeout: time.Second * 5,
	})
	if err != nil {
		logrus.Fatalln(err)
	}
	defer cli.Close()

	ctx, cancel := context.WithCancel(context.Background())

	//str2 := `[{"path":"F:/kafka/web_log/web.log","topic":"web_log"},{"path":"F:/kafka/web_log/sql.log","topic":"sql_log"}]`
	str2 := `[{"path":"F:/kafka/web_log/web.log","topic":"web_log"},{"path":"F:/kafka/web_log/sql.log","topic":"sql_log"},{"path":"F:/kafka/web_log/nginx.log","topic":"nginx_log"}]`
	//put
	_, err = cli.Put(ctx, "collect_log", str2)
	if err != nil {
		cancel()
		logrus.Fatalln(err)
	}
	cancel()

	//get
	resp, err := cli.Get(context.Background(), "collect_log")
	if err != nil {
		//cancel()
		logrus.Fatalln(err)
	}

	for _, ev := range resp.Kvs {
		fmt.Printf("key: %s , val: %s\n", ev.Key, ev.Value)
	}
	//cancel()

	//del
	//_, err = cli.Delete(context.Background(), "collect_log")
	//if err != nil {
	//	logrus.Fatalln(err)
	//}
}
